import 'dart:convert' show json;

import 'HomeData.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class VodDetails {
  VodDetails({
    this.comments,
    this.count,
    this.domain,
    this.rand,
    this.relate,
    this.shareLink,
    this.status,
    this.vod,
  });

  factory VodDetails.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Comments> comments = jsonRes['comments'] is List ? <Comments>[] : null;
    if (comments != null) {
      for (final dynamic item in jsonRes['comments']) {
        if (item != null) {
          comments.add(Comments.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }

    final List<HomeDataItem> rand = jsonRes['rand'] is List ? <HomeDataItem>[] : null;
    if (rand != null) {
      for (final dynamic item in jsonRes['rand']) {
        if (item != null) {
          rand.add(HomeDataItem.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }

    final List<HomeDataItem> relate = jsonRes['relate'] is List ? <HomeDataItem>[] : null;
    if (relate != null) {
      for (final dynamic item in jsonRes['relate']) {
        if (item != null) {
          relate.add(HomeDataItem.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return VodDetails(
      comments: comments,
      count: asT<int>(jsonRes['count']),
      domain: asT<String>(jsonRes['domain']),
      rand: rand,
      relate: relate,
      shareLink: asT<String>(jsonRes['shareLink']),
      status: asT<int>(jsonRes['status']),
      vod: Vod.fromJson(asT<Map<String, dynamic>>(jsonRes['vod'])),
    );
  }

  List<Comments> comments;
  int count;
  String domain;
  List<HomeDataItem> rand;
  List<HomeDataItem> relate;
  String shareLink;
  int status;
  Vod vod;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'comments': comments,
        'count': count,
        'domain': domain,
        'rand': rand,
        'relate': relate,
        'shareLink': shareLink,
        'status': status,
        'vod': vod,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Comments {
  Comments({
    this.commentID,
    this.commentType,
    this.commentVid,
    this.commentHide,
    this.commentIp,
    this.userID,
    this.commentName,
    this.commentContent,
    this.commentReply,
    this.commentTime,
  });

  factory Comments.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : Comments(
          commentID: asT<int>(jsonRes['CommentID']),
          commentType: asT<int>(jsonRes['CommentType']),
          commentVid: asT<String>(jsonRes['CommentVid']),
          commentHide: asT<int>(jsonRes['CommentHide']),
          commentIp: asT<int>(jsonRes['CommentIp']),
          userID: asT<int>(jsonRes['UserID']),
          commentName: asT<String>(jsonRes['CommentName']),
          commentContent: asT<String>(jsonRes['CommentContent']),
          commentReply: asT<String>(jsonRes['CommentReply']),
          commentTime: asT<int>(jsonRes['CommentTime']),
        );

  int commentID;
  int commentType;
  String commentVid;
  int commentHide;
  int commentIp;
  int userID;
  String commentName;
  String commentContent;
  String commentReply;
  int commentTime;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'CommentID': commentID,
        'CommentType': commentType,
        'CommentVid': commentVid,
        'CommentHide': commentHide,
        'CommentIp': commentIp,
        'UserID': userID,
        'CommentName': commentName,
        'CommentContent': commentContent,
        'CommentReply': commentReply,
        'CommentTime': commentTime,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

class VodClass {
  VodClass({
    this.typeID,
    this.typeName,
  });

  factory VodClass.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : VodClass(
          typeID: asT<int>(jsonRes['TypeID']),
          typeName: asT<String>(jsonRes['TypeName']),
        );

  int typeID;
  String typeName;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'TypeID': typeID,
        'TypeName': typeName,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Vod {
  Vod({
    this.vodID,
    this.vodLevel,
    this.typeID,
    this.typeID1,
    this.groupID,
    this.vodUp,
    this.vodName,
    this.vodPic,
    this.vodActor,
    this.vodDirector,
    this.vodBlurb,
    this.vodContent,
    this.vodYear,
    this.vodScore,
    this.vodScoreAll,
    this.vodHits,
    this.vodScoreNum,
    this.vodArea,
    this.vodRemarks,
    this.vps,
    this.vpf,
    this.vpl,
    this.vodHitsWeek,
    this.vodTime,
    this.vodPlayServer,
    this.vodPlayUrls,
    this.vodClass,
  });

  factory Vod.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<VodPlayServer> vodPlayServer = jsonRes['VodPlayServer'] is List ? <VodPlayServer>[] : null;
    if (vodPlayServer != null) {
      for (final dynamic item in jsonRes['VodPlayServer']) {
        if (item != null) {
          vodPlayServer.add(VodPlayServer.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return Vod(
      vodID: asT<int>(jsonRes['VodID']),
      vodLevel: asT<int>(jsonRes['VodLevel']),
      typeID: asT<int>(jsonRes['TypeID']),
      typeID1: asT<int>(jsonRes['TypeID1']),
      groupID: asT<int>(jsonRes['GroupID']),
      vodUp: asT<int>(jsonRes['VodUp']),
      vodName: asT<String>(jsonRes['VodName']),
      vodPic: asT<String>(jsonRes['VodPic']),
      vodActor: asT<String>(jsonRes['VodActor']),
      vodDirector: asT<String>(jsonRes['VodDirector']),
      vodBlurb: asT<String>(jsonRes['VodBlurb']),
      vodContent: asT<String>(jsonRes['VodContent']),
      vodYear: asT<String>(jsonRes['VodYear']),
      vodScore: asT<int>(jsonRes['VodScore']),
      vodScoreAll: asT<int>(jsonRes['VodScoreAll']),
      vodHits: asT<int>(jsonRes['VodHits']),
      vodScoreNum: asT<int>(jsonRes['VodScoreNum']),
      vodArea: asT<String>(jsonRes['VodArea']),
      vodRemarks: asT<String>(jsonRes['VodRemarks']),
      vps: asT<String>(jsonRes['Vps']),
      vpf: asT<String>(jsonRes['Vpf']),
      vpl: asT<String>(jsonRes['Vpl']),
      vodHitsWeek: asT<String>(jsonRes['VodHitsWeek']),
      vodTime: asT<int>(jsonRes['VodTime']),
      vodPlayServer: vodPlayServer,
      vodPlayUrls: vodPlayUrlsfromJson(asT<Map<String, dynamic>>(jsonRes['VodPlayUrls'])),
      vodClass: VodClass.fromJson(asT<Map<String, dynamic>>(jsonRes['VodClass'])),
    );
  }

  int vodID;
  int vodLevel;
  int typeID;
  int typeID1;
  int groupID;
  int vodUp;
  String vodName;
  String vodPic;
  String vodActor;
  String vodDirector;
  String vodBlurb;
  String vodContent;
  String vodYear;
  int vodScore;
  int vodScoreAll;
  int vodHits;
  int vodScoreNum;
  String vodArea;
  String vodRemarks;
  String vps;
  String vpf;
  String vpl;
  String vodHitsWeek;
  int vodTime;
  List<VodPlayServer> vodPlayServer;
  Map<String, List<List<String>>> vodPlayUrls;
  VodClass vodClass;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'VodID': vodID,
        'VodLevel': vodLevel,
        'TypeID': typeID,
        'TypeID1': typeID1,
        'GroupID': groupID,
        'VodUp': vodUp,
        'VodName': vodName,
        'VodPic': vodPic,
        'VodActor': vodActor,
        'VodDirector': vodDirector,
        'VodBlurb': vodBlurb,
        'VodContent': vodContent,
        'VodYear': vodYear,
        'VodScore': vodScore,
        'VodScoreAll': vodScoreAll,
        'VodHits': vodHits,
        'VodScoreNum': vodScoreNum,
        'VodArea': vodArea,
        'VodRemarks': vodRemarks,
        'Vps': vps,
        'Vpf': vpf,
        'Vpl': vpl,
        'VodHitsWeek': vodHitsWeek,
        'VodTime': vodTime,
        'VodPlayServer': vodPlayServer,
        'VodPlayUrls': vodPlayUrls,
        'VodClass': vodClass,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

class VodPlayServer {
  VodPlayServer({
    this.status,
    this.from,
    this.show,
    this.des,
    this.ps,
    this.target,
    this.parse,
    this.sort,
    this.tip,
    this.iD,
  });

  factory VodPlayServer.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : VodPlayServer(
          status: asT<String>(jsonRes['Status']),
          from: asT<String>(jsonRes['From']),
          show: asT<String>(jsonRes['Show']),
          des: asT<String>(jsonRes['Des']),
          ps: asT<String>(jsonRes['Ps']),
          target: asT<String>(jsonRes['Target']),
          parse: asT<String>(jsonRes['Parse']),
          sort: asT<String>(jsonRes['Sort']),
          tip: asT<String>(jsonRes['Tip']),
          iD: asT<String>(jsonRes['ID']),
        );

  String status;
  String from;
  String show;
  String des;
  String ps;
  String target;
  String parse;
  String sort;
  String tip;
  String iD;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'Status': status,
        'From': from,
        'Show': show,
        'Des': des,
        'Ps': ps,
        'Target': target,
        'Parse': parse,
        'Sort': sort,
        'Tip': tip,
        'ID': iD,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

Map<String, List<List<String>>> vodPlayUrlsfromJson(Map<String, dynamic> jsonRes) {
  if (jsonRes == null) {
    return null;
  }
  Map<String, List<List<String>>> map = Map();
  jsonRes.forEach((key, value) {
    final List<List<String>> dataList = jsonRes[key] is List ? <List<String>>[] : null;
    if (dataList != null) {
      for (final dynamic item0 in asT<List<dynamic>>(jsonRes[key])) {
        if (item0 != null) {
          final List<String> items1 = <String>[];
          for (final dynamic item1 in asT<List<dynamic>>(item0)) {
            if (item1 != null) {
              items1.add(asT<String>(item1));
            }
          }
          dataList.add(items1);
        }
      }
    }
    map[key] = dataList;
  });
  return map;
}
